package SOSO;

import java.util.*;

public class Test {
    static Map<String, MobileCard> mobileCards = new HashMap<>();
    static Map<String, List<ConsumInfo>> consumInfos = new HashMap<>();
    static List<ConsumInfo> consumInfoList = new ArrayList<>();

    public static void main(String[] args) {
        System.out.println("*********欢迎来到嗖嗖移动业务中心*********");
        Scanner input = new Scanner(System.in);
        while (true) {
            System.out.println("1、用户登录");
            System.out.println("2、用户注册");
            System.out.println("3、使用嗖嗖");
            System.out.println("4、话费充值");
            System.out.println("5、资费说明");
            System.out.println("6、退出系统");
            System.out.print("请选择：");
            int choose = input.nextInt();
            switch (choose) {
                case 1:
                    System.out.println("请输入卡号：");
                    String cardNumber = input.next();
                    System.out.println("请输入密码：");
                    String passWord = input.next();
                    Menu menu = new Menu();
                    do {
                        boolean index = menu.menu(cardNumber, passWord);
                        if (!index) {
                            System.out.println("卡号与密码不匹配");
                            break;
                        }
                        if (index) {
                            System.out.println("请选择；");
                            int ch = input.nextInt();
                            if (ch == 1) {
                                menu.showAmounDetail(cardNumber);
                            } else if (ch == 2) {
                                menu.showRemainDetail(mobileCards.get(cardNumber));
                            } else if (ch == 3) {
                                menu.printConsumInfo(cardNumber);
                            } else if (ch == 4) {
                                menu.changePackage(cardNumber);
                            } else if (ch == 5) {
                                menu.remove(cardNumber);
                                break;
                            }
                        }
                        System.out.println("输入(1~9)返回当前列表，0返回上级！");
                    } while (input.nextInt() != 0);

                    break;
                case 2:
                    String[] numbers = new String[9];
                    ServicePackage servicePackage = null;
                    int choose2;
                    while (true) {
                        System.out.println("*******可选择的卡号*******");
                        for (int i = 1; i < 10; i++) {
                            Set<String> set1 = mobileCards.keySet();
                            StringBuffer num = new StringBuffer();
                            for (int j = 0; j < 8; j++) {
                                Integer t = (int) (Math.random() * 10);
                                num.append(t.toString());
                            }
                            String number = "139" + num.toString();
                            numbers[i - 1] = number;
                            System.out.print(i + "、" + number + "   ");
                            if (i % 3 == 0) {
                                System.out.println();
                            }
                        }
                        System.out.println("请选择序号（1~9）");
                        try {
                            choose2 = input.nextInt();
                            if (choose2 < 1 || choose2 > 9) {
                                throw new Exception();
                            } else {
                                break;
                            }
                        } catch (Exception e) {
                            System.out.println("请输入正确的序号");
                        }
                    }
                    while (true) {
                        System.out.println("1、话痨套餐");
                        System.out.println("2、网虫套餐");
                        System.out.println("3、超人套餐");
                        System.out.print("请选择序号：");
                        int ch = 0;
                        try {
                            ch = input.nextInt();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (ch == 1) {
                            servicePackage = new TalkPackage();
                            break;
                        } else if (ch == 2) {
                            servicePackage = new NetPackage();
                            break;
                        } else if (ch == 3) {
                            servicePackage = new SuperPackage();
                            break;
                        } else {
                            System.out.println("选择错误，请重新选择！");
                        }
                    }
                    System.out.println("请输入你的姓名：");
                    String name = input.next();
                    System.out.println("请输入你的密码：");
                    String password = input.next();
                    double money;
                    while (true) {
                        System.out.println("请输入预存金额：");
                        try {
                            money = input.nextDouble();
                            if (money < servicePackage.getPrice()) {
                                System.out.println("预存金额小于月资费，请重新输入");
                            } else {
                                break;
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println("注册成功!");
                    MobileCard mobileCard = new MobileCard(numbers[choose2 - 1].toString(), name, password, servicePackage,
                            servicePackage.getPrice(), (money - servicePackage.getPrice()));
                    mobileCards.put(numbers[choose2 - 1].toString(), mobileCard);
                    consumInfos.put(numbers[choose2 - 1].toString(), null);
                    mobileCard.showMeg();
                    break;
                case 3:
                    System.out.println("请输入卡号：");
                    String cardNumber3 = input.next();
                    UseSoso useSoso = new UseSoso();
                    useSoso.use(cardNumber3);
                    break;
                case 4:
                    System.out.println("请问给哪张卡充值？");
                    String number4 = input.next();
                    Set<String> set1 = mobileCards.keySet();
                    boolean index4 = false;
                    for (String s : set1) {
                        if (s.equals(number4)) {
                            System.out.println("请问充值多少钱?");
                            mobileCards.get(s).setMoney(mobileCards.get(s).getMoney() + input.nextDouble());
                            System.out.println("充值成功！");
                            index4 = true;
                        }
                    }
                    if (!index4) {
                        System.out.println("没有这张卡！");
                    }
                    break;
                case 5:
                    ServicePackage s = null;
                {
                    s = new NetPackage();
                    s.showInfo();
                    System.out.println();
                }
                {
                    s = new TalkPackage();
                    s.showInfo();
                    System.out.println();
                }
                {
                    s = new SuperPackage();
                    s.showInfo();
                }
                break;
                case 6:
                    System.exit(1);

            }
        }
    }
}
